from fastapi import APIRouter, Depends
from pydantic import BaseModel
from app.core.workflow_engine import WorkflowEngine

router = APIRouter()

class ChatRequest(BaseModel):
    message: str
    user_id: str = "cai"  # 默认用户ID

@router.post("/chat")
async def process_chat(request: ChatRequest):
    try:
        # 初始化工作流引擎
        engine = WorkflowEngine(user_id=request.user_id)
        
        # 处理用户查询
        result = engine.process_query(request.message)
        
        return {
            "success": True,
            "response": result["response"],
            "visualization": result["visualization"]
        }
    except Exception as e:
        return {
            "success": False,
            "error": str(e)
        }